<?php

namespace Home\Controller;

use Think\Controller;
use Think\Log;
use QL\QueryList;
use Org\Util\String;


//import("Home.Library.Think.QL.QueryList");

class Baiduwm
{
    private $dbdingdan = array();
    private $dbsubdingdan = array();

    private $filename = "/Users/jdong/project/xbbcrm/tpxbb/public/pc/201602baidudb";
    private $subfilename = "/Users/jdong/project/xbbcrm/tpxbb/public/pc/201602baidusubdb";

    private $pcDir = "/Users/jdong/project/xbbcrm/tpxbb/public/pc/";


    private $dmid = "xiababybaidu";//"xbbxjkd";
    private $suffix = "xiababybaidu";

    private $filePrefix = "";//"20160331xiababy";


    public function index()
    {
        // $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }


    public function login($daterange)
    {


        $cookie = "BAIDUID=DADB7BB2217993A067F6DC75A4CF6642:FG=1; PSTM=1434621019; BIDUPSID=71E94451B345653D4038718F24BEFC98; BDUSS=2dzcFVGTVZYTmZZZ0czRWM5b1BWb1R3VG5sM2VMbk44Q0dFWkRDSEkycUI4M2hXQVFBQUFBJCQAAAAAAAAAAAEAAACweqYOamlkb25nMTE0XzIwMTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIFmUVaBZlFWT; WMUSS=YDAABnDFBSS3xmdxRaLC8jbV5jY3lfIEJiMGheIVxCf0w6Z1cLOSIIIBobeUZK3lAAAHTMofxciXjZjQWVMIAcpYQd0HG1MJyduLkYISEBNElwBOlwXWztMP3syDBs5NHw%7EKBktcz9TYWwaaTVaN0Y2N38STltMdFq9ABpgWxHxnkQRiVu1EU3-IxY0CQAAH; new_order_time=1457613943; new_remind_time=1457613914; _wmcrmpush=E06311CB4FB65F155633CFB8586881D3_1457613944_10_1533034181_xiababy0; ULOG_UID=ilm9pi0h60r; newyear=open";

        $cookie = preg_replace('/[\r\n]+/', '', $cookie);


        $start = date("Y-m-d", strtotime($daterange[0]));
        $end = date("Y-m-d", strtotime($daterange[1]));


        $start2 = date("Ymd", strtotime($daterange[0]));
        $end2 = date("Ymd", strtotime($daterange[1]));

//		echo  $start,$end,$start2,$end2;

        $this->filePrefix = $start2 . "-" . $end2 . $this->suffix;


        $keyword = "顾客电话";

        for ($x = 1; $x < 50; $x++) {

            $url = "http://wmcrm.baidu.com/crm?qt=orderlist&order_status=0&start_time=" . $start . "&end_time=" . $end . "&pay_type=2&is_asap=0&page=" . $x;
            $filename = $this->pcDir . $this->filePrefix . $x;


            $res = Method::getPage($url, $cookie, $filename, $keyword);


            if (!$res) {
                Log::record("total page=" . $x, "DEBUG");

                Log::record("filePrefix=" .  $this->filePrefix, "DEBUG");
                break;

            }


        }


    }

    public function dealbdcsv()
    {

        // 载入文件，基于服务器的路径

        // 遍历pc目录下所有缓存文件
        // $path = C ( 'WM_UPLOAD' );
        $path = C('SS_CACHEPATH');
        $uri = C('XBB_URI');
        $mydir = dir($path);


        // $url="http://localhost/tpxbb/public/pc/20151201-20151231-46";

        // $this->dealcsv ( $url );

        while ($file = $mydir->read()) {

            $filename = $path . $file;


            if (!is_dir("$filename")) {

                $url = $uri . $path . $file;
                $posbdfile = stripos($file, substr($this->filePrefix,9,12));

                if (intval($posbdfile) > 0) {
                    Log::record($filename, "DEBUG");//. "</br>";

                    $this->dealcsv($filename);

//                    $this->dealcsv($url);


                }
            }
        }

        $mydir->close();
//		return;
        // 序列化 两个数组


        Log::record("dingdancount=" . count($this->dbdingdan), "DEBUG");

        $this->saveDb();

        return;

//        $db = json_encode($this->dbdingdan);
//        $db2 = json_encode($this->dbsubdingdan);
//
////        if (!file_exists($this->filename))
//        {
//            $res = file_put_contents($this->filename, $db);
//        }
//
////        if (!file_exists($this->subfilename))
//        {
//            $res = file_put_contents($this->subfilename, $db2);
//        }
//
//        $this->db();
    }


    public function saveDb()
    {


        $dingdandb = D("dingdan");


        foreach ($this->dbdingdan as $key => $value) {
            try {

                $dingdandb->add($value);
            } catch (\Think\Exception $e) {

                Log::record($e->getMessage(), "ERR");;
            }

        }


        $dingdandb = D("subdingdan");

        foreach ($this->dbsubdingdan as $key => $value) {


            try {

//                $dingdandb->add($value);
            } catch (\Think\Exception $e) {

                Log::record($e->getMessage(), "ERR");;
            }

        }


    }


    /**
     * 反序列化后只做db操作
     */
    public function db()
    {

//		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
        $filename = $this->filename;    //"/Users/jdong/project/tpxbb/public/pc/201510db";
        $subfilename = $this->subfilename;   // "/Users/jdong/project/tpxbb/public/pc/201510subdb";

        if (file_exists($filename)) {

            $res = file_get_contents($filename);

            $dbdingdan = json_decode($res, true);

            // var_dump($dbdingdan);

            // echo " total=" . Count ( $dbdingdan ) . "</br>";

            $dingdandb = D("dingdan");
            $list = $dingdandb->field("ddid")->select();
            $ddidarray = array();
            // 拼接所有的ddid
            foreach ($list as $key => $value) {
                array_push($ddidarray, $value ["ddid"]);
            }

            $i = 0;
            $p = 0;
            foreach ($dbdingdan as $key => $value) {
                if (!in_array($key, $ddidarray, false)) {

                    // 需要添加到数据库中去
                    $p++;

                    try {

                        $dingdandb->add($value);
                    } catch (\Think\Exception $e) {

                        Log::record("添加订单失败 " . $e->getMessage(), "DEBUG");;
                    }
                }
            }


        }

        if (file_exists($subfilename)) {

            $res = file_get_contents($subfilename);

            $dbdingdan = json_decode($res, true);

            // var_dump($dbdingdan);

            $dingdandb = D("subdingdan");
            $list = $dingdandb->field("subid")->select();
            $ddidarray = array();
            // 拼接所有的ddid
            foreach ($list as $key => $value) {
                array_push($ddidarray, $value ["subid"]);
            }

            $i = 0;
            $p = 0;
            foreach ($dbdingdan as $key => $value) {
                if (!in_array($key, $ddidarray, false)) {

                    // 需要添加到数据库中去
                    $p++;

                    try {

                        $dingdandb->add($value);
                    } catch (\Think\Exception $e) {

                        Log::record("添加订单失败 " . $e->getMessage(), "ERR");;
                    }
                }
            }


        }
    }



    function dealcsv($filename)
    {
        echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";


        Log::record($url, "DEBUG");

        $datas = array();
        $menus = array();

        $this->dealfunctionorder($url, $datas, $menus);

        $reg = array(

            'div' => array(

                'div',
                'text'
            )
        );


        $html = file_get_contents ( $filename );

        $ql = QueryList::Query ( $html, $reg );


        $rowline = $ql->data();

        $obj = $rowline [0];
        $rownum = count($rowline);

        Log::record("rownum=" . $rownum, "DEBUG");


        $content = "";

        foreach ($rowline [0] as $keys => $values) {

            $content = $values;
        }


        $dingdan = explode('#', $content);



        for ($x = 0; $x < $rownum; $x++) {

            // echo "</br>x=".$x." ".$dingdan [$x] . "</br></br>";

            $data = $this->dealbditem($dingdan [$x]);

            if ($data != null) {

                $ddid = $data ["ddid"];
                $intddid = ( int )$data ["ddid"];

                if ($menus [$ddid]) {
                    $data ["menu"] = trim($menus [$ddid]);
                    $data ["sub_men"] = 1;
                } else if ($menus [$intddid]) {
                    $data ["menu"] = trim($menus [$intddid]);
                    $data ["sub_menu"] = 1;
                }

                $data ["price"] = trim($data ["userpay"]);
                $this->dbdingdan [$ddid] = $data;


            }
        }
    }


//    function dealcsv($url)
//    {
//        echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
//
//        // $path = C ( 'SS_CACHEPATH' );
//        // $uri = C ( 'XBB_URI' );
//        // $url = $uri . $path . "20151201-20151231-46";
//
//        // // $url="http://localhost/tpxbb/public/pcdb/20151201-20151231-1";
//        // // $url ="http://localhost/tpxbb/public/pc/2016-01-17_2016-01-03_46";
//        // echo $url;
//
//        Log::record($url, "DEBUG");
//
//        $datas = array();
//        $menus = array();
//
//        $this->dealfunctionorder($url, $datas, $menus);
//
//        $reg = array(
//
//            'div' => array(
//
//                'div',
//                'text'
//            )
//        );
//
//        // $reg = array( 'info'=>array('.taskInfo','text'));
//
//        $hj = new \QueryList ($url, $reg);
//
//        $rowarray = $hj->getJSON();
//
//        $rowline = json_decode($rowarray);
//
//        $obj = $rowline [0];
//        $rownum = count($rowline);
//
//        Log::record("rownum=" . $rownum, "DEBUG");
//
//
//        $content = "";
//
//        foreach ($rowline [0] as $keys => $values) {
//
//            $content = $values;
//        }
//        // echo $content;
////        Log::record($content,"DEBUG");
//
//        $dingdan = explode('#', $content);
//
////        $dingdandb = D("dingdan");
//        // $list = $dingdandb->field ( "ddid" )->select ();
//        // var_dump ( $list );
//
//        // foreach ($menus as $key => $value) {
//        // echo "deal csv menu key=".$key." type=".gettype($key)."</br>";
//        // }
//
//        for ($x = 0; $x < $rownum; $x++) {
//
//            // echo "</br>x=".$x." ".$dingdan [$x] . "</br></br>";
//
//            $data = $this->dealbditem($dingdan [$x]);
//
//            if ($data != null) {
//
//                $ddid = $data ["ddid"];
//                $intddid = ( int )$data ["ddid"];
//
//                if ($menus [$ddid]) {
//                    $data ["menu"] = trim($menus [$ddid]);
//                    $data ["sub_men"] = 1;
//                } else if ($menus [$intddid]) {
//                    $data ["menu"] = trim($menus [$intddid]);
//                    $data ["sub_menu"] = 1;
//                }
//
//                $data ["price"] = trim($data ["userpay"]);
//
//                // var_dump ( $data );
//                // echo $data ["ddid"]." type=".gettype($data ["ddid"])."</br>";
//
//                // 存入数据库
////                try {
//
//                // if (in_array ( $data ["ddid"], $list,false )) {
//                // echo "exist dingdan</br>";
//                // } else {
//                // echo "not exist dingdan</br>";
//                // // $dingdandb->add ( $data );
//                // }
//
//                $this->dbdingdan [$ddid] = $data;
//
//
////                } catch (\Think\Exception $e) {
////
////                    Log::record( $e->getMessage() ,"ERR");
////                }
//            }
//        }
//    }

    public function dealbditem($item)
    {
        // 要 订单号,顾客id，下单时间, 顾客电话, 菜品

        /**
         *
         * item=16
         * x=0 83订单号
         *
         * x=1 14515762535828 下单时间
         *
         * x=2 2015-12-31 23:38:11 订单金额
         *
         * x=3 ￥149.00 订单状态
         *
         * x=4 已完成 打印 复制 顾客ID
         *
         * x=5 showshow41 顾客订单记录(88%) 顾客姓名
         *
         * x=6 李 女士 顾客电话
         *
         * x=7 13488660682 顾客地址
         *
         * x=8 东湖湾 1期八号楼2单元2001 × 查看地图 经百度地图校验，该地址可配送。门店与送货地址的直线距离为
         *
         * x=9 米。(本数据仅供参考) 经百度地图校验，该地址不在配送范围内，门店与送货地址的直线距离为
         *
         * x=10 米。由于地图校验存在一定的误差，建议您进行电话确认。(本数据仅供参考。) 没有在百度地图上找到该地址。由于地图校验存在一定的误差，建议您进行电话确认。(本数据仅供参考) 订单备注
         *
         * x=11 期望时间
         *
         * x=12 立即送餐 确认出餐时间
         *
         * x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 不拘一蛤（辣炒花蛤） 38.00 1 38.00 经典簋街麻小（1斤装） 99.00 1 99.00 小计
         *
         * x=14 137.00 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 立减优惠 -13 总计
         *
         * x=15 149.00
         *
         *
         *
         *
         *
         * x=4 已完成 打印 复制 顾客ID
         *
         * x=5 呆野熊 顾客订单记录(75%) 顾客姓名
         *
         * x=6 张泽宜 先生 顾客电话
         *
         * x=7 18211187674 顾客地址
         *
         * x=8 外馆斜街6号院 北京市朝阳区安定门外外馆斜街1号 × 查看地图 经百度地图校验，该地址可配送。门店与送货地址的直线距离为
         *
         * x=9 米。(本数据仅供参考) 经百度地图校验，该地址不在配送范围内，门店与送货地址的直线距离为
         *
         * x=10 米。由于地图校验存在一定的误差，建议您进行电话确认。(本数据仅供参考。) 没有在百度地图上找到该地址。由于地图校验存在一定的误差，建议您进行电话确认。(本数据仅供参考) 订单备注
         *
         * x=11 期望时间
         *
         * x=12 立即送餐 确认出餐时间
         *
         * x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 思念炒饭（小龙虾炒饭） 35.00 2 70.00 ¥9.9特价吮指卤腐竹 9.90 1 9.90 小计
         *
         * x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 20.00 外卖餐饮专享券 -10 总计
         *
         * x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 20.00 立减优惠 -8 总计
         *
         * x=13 1970-01-01 08:00:00 大金额 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 0.00 特价优惠 -92 总计
         *
         * x=14 79.90 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 总计
         *
         * x=15 104.90
         *
         *
         * ["menu"]=> string(343) "1970-01-01 08:00:00 发票信息浙江东阳均城影视科技有限公司 发票金额187.90元
         * 在线支付 菜品 单价 数量 金额 不拘一蛤（辣炒花蛤） 38.00 1 38.00 经典簋街麻小（1斤装） 99.00 1 99.00 思念炒饭（小龙虾炒饭） 35.00 1 35.00 ¥9.9特价－私房卤豆皮 9.90 1 9.90 小计"
         *
         * @var unknown
         */
        $resding = array();
        $dingdan = explode('：', $item);

        $rownum = count($dingdan);

        if ($rownum < 15) {
            return null;
        }

        // echo "item=" . $rownum . "</br>";
        // for($x = 0; $x < $rownum; $x ++) {

        // echo "x=" . $x . " " . $dingdan [$x] . "</br></br>";
        // }

        $listitem = $dingdan [1];

        $pos = stripos($listitem, "下单时间");

        // if($pos<10)
        // {return;}

        $resding ["ddid"] = trim(substr($listitem, 0, $pos));

        $listitem = $dingdan [2];
        $pos = stripos($listitem, "订单金额");
        $ordertime = substr($listitem, 0, $pos);
        $ordertime = date("Y-m-d H:i:s", strtotime($ordertime));

        $resding ["ordertime"] = $ordertime;

        // x=3 ￥149.00 订单状态

        // x=4 已完成 打印 复制 顾客ID

        // x=5 showshow41 顾客订单记录(88%) 顾客姓名

        // x=6 李 女士 顾客电话

        // x=7 13488660682 顾客地址

        // x=8 东湖湾 1期八号楼2单元2001 ×

        $listitem = $dingdan [3];
        $pos = stripos($listitem, "订单状态");
        $posdot = stripos($listitem, ".");
        $posstart = stripos($listitem, "￥");
        $userpay = substr($listitem, $posstart + strlen("￥"), $posdot + 3 - $posstart - strlen("￥"));
        $resding ["userpay"] = trim($userpay);
        $listitem = $dingdan [4];
        $pos = stripos($listitem, "已完成");

        if ($pos >= 0 && strlen($pos) > 0) {
            $resding ["status"] = 1;
        } else {
            $resding ["status"] = 0;
        }

        $listitem = $dingdan [6];
        $pos = stripos($listitem, "顾客电话");

        $sex = "女士";
        $possex = stripos($listitem, $sex);
        if ($possex > 0) {
            $resding ["sex"] = 0;
            $resding ["name"] = substr($listitem, 0, $possex);
        } else {
            $resding ["sex"] = 1;
            $sex = "先生";
            $possex = stripos($listitem, $sex);

            if ($possex > 0) {
                $resding ["name"] = substr($listitem, 0, $possex);
            } else {
                $resding ["name"] = substr($listitem, 0, $pos);
            }
        }
        $resding ["name"] = trim($resding ["name"]);

        $listitem = $dingdan [7];
        $pos = stripos($listitem, "顾客地址");
        $resding ["mobile"] = trim(substr($listitem, 0, $pos));

        $listitem = $dingdan [8];
        $pos = stripos($listitem, "×");
        $resding ["address"] = trim(substr($listitem, 0, $pos));

        $listitem = $dingdan [11];
        $pos = stripos($listitem, "期望时间");
        $resding ["memo"] = substr($listitem, 0, $pos);

        // x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 20.00 外卖餐饮专享券 -10 总计
        //
        // x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 20.00 立减优惠 -8 总计
        //
        // x=13 1970-01-01 08:00:00 大金额 在线支付 菜品 单价 数量 金额 其他费用 金额 餐盒费 0.00 外卖配送费 0.00 特价优惠 -92 总计

        $wmyh = "外卖餐饮专享券";
        $ljyh = "立减优惠";

        $tjyh = "特价优惠";

        $listitem = $dingdan [13];
        $pos = stripos($listitem, "总计");
        // $resding ["memo"] = substr ( $listitem, 0, $pos );

        $poswm = stripos($listitem, $wmyh);
        $poslj = stripos($listitem, $ljyh);
        $postj = stripos($listitem, $tjyh);
        if ($poswm > 0) {
            $resding ["platpay"] = substr($listitem, $poswm + strlen($wmyh), $pos - $poswm - strlen($wmyh));
        }

        if ($poslj > 0) {
            $resding ["platpay"] = substr($listitem, $poslj + strlen($ljyh), $pos - $poslj - strlen($ljyh));
        }

        if ($postj > 0) {
            $resding ["bosspay"] = substr($listitem, $postj + strlen($tjyh), $pos - $postj - strlen($tjyh));
        }

        // x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 思念炒饭（小龙虾炒饭） 35.00 2 70.00 ¥9.9特价吮指卤腐竹 9.90 1 9.90 小计

        // x=14 79.90 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 总计

        // x=15 104.90

        // ["menu"]=> string(343) "1970-01-01 08:00:00 发票信息浙江东阳均城影视科技有限公司 发票金额187.90元
        // 在线支付 菜品 单价 数量 金额 不拘一蛤（辣炒花蛤） 38.00 1 38.00 经典簋街麻小（1斤装） 99.00 1 99.00 思念炒饭（小龙虾炒饭） 35.00 1 35.00 ¥9.9特价－私房卤豆皮 9.90 1 9.90 小计"

        // x=13 1970-01-01 08:00:00 发票信息

        // x=14 浙江东阳均城影视科技有限公司 发票金额

        // x=15 187.90元 在线支付 菜品 单价 数量 金额 不拘一蛤（辣炒花蛤） 38.00 1 38.00 经典簋街麻小（1斤装） 99.00 1 99.00 思念炒饭（小龙虾炒饭） 35.00 1 35.00 ¥9.9特价－私房卤豆皮 9.90 1 9.90 小计

        // x=16 181.90 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 立减优惠 -19 总计

        // x=17 187.90

        $caipin = "金额";

        if ($rownum == 15) {

            $listitem = $dingdan [13];

            $pos = stripos($listitem, $caipin);
            $menu = substr($listitem, $pos + strlen($caipin));

            $listitem3 = $dingdan [14];
            $pos = stripos($listitem3, "顾客订单记录");

            if ($pos > 0) {
                // ["menu"]=> string(801) "菜品 单价 数量 金额 皮皮虾大战醉蟹 167.00 1 167.00 乐此不皮（椒盐皮皮虾） 88.00 1 88.00 小计 255.00 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 特价优惠 -128 特价商品抽佣返还 6.40 总计 152.00 顾客订单记录 × 拒绝订单 请选择拒绝原因 美食已售完 重复订单 联系不上用户 不在配送范围 假订单 餐厅太忙 请输入拒绝原因 确定 取消订单 请选择取消原因 美食已售完 重复订单 联系不上用户 不在配送范围 假订单 餐厅太忙 用户致电取消 请输入取消原因 确定 配送方式 物流、快递 自己配送 物流公司 -请选择- 快递单号 看看东西到哪了>> 取消 确定" }

                $listitem3 = substr($listitem3, 0, $pos);
            }

            $resding ["menu"] = $menu . $listitem3;
        } else if ($rownum == 16) {

            // x=13 1970-01-01 08:00:00 在线支付 菜品 单价 数量 金额 不拘一蛤（辣炒花蛤） 38.00 1 38.00 经典簋街麻小（1斤装） 99.00 1 99.00 小计

            $listitem = $dingdan [13];
            $pos = stripos($listitem, $caipin);
            $menu = substr($listitem, $pos + strlen($caipin));

            $listitem3 = $dingdan [15];
            $pos = stripos($listitem3, "顾客订单记录");

            if ($pos > 0) {
                // ["menu"]=> string(801) "菜品 单价 数量 金额 皮皮虾大战醉蟹 167.00 1 167.00 乐此不皮（椒盐皮皮虾） 88.00 1 88.00 小计 255.00 其他费用 金额 餐盒费 0.00 外卖配送费 25.00 特价优惠 -128 特价商品抽佣返还 6.40 总计 152.00 顾客订单记录 × 拒绝订单 请选择拒绝原因 美食已售完 重复订单 联系不上用户 不在配送范围 假订单 餐厅太忙 请输入拒绝原因 确定 取消订单 请选择取消原因 美食已售完 重复订单 联系不上用户 不在配送范围 假订单 餐厅太忙 用户致电取消 请输入取消原因 确定 配送方式 物流、快递 自己配送 物流公司 -请选择- 快递单号 看看东西到哪了>> 取消 确定" }

                $listitem3 = substr($listitem3, 0, $pos);
            }

            $resding ["menu"] = $menu . $dingdan [14] . $listitem3;
        } else if ($rownum > 16) {

            $listitem = $dingdan [15];

            $pos = stripos($listitem, "在线支付");

            $invoice = $dingdan [14] . substr($listitem, 0, $pos);
            $resding ["invoice"] = trim($invoice);

            $pos = stripos($listitem, $caipin);
            $menu = substr($listitem, $pos + strlen($caipin));

            $listitem3 = $dingdan [17];

            $resding ["menu"] = $menu . $dingdan [16] . $listitem3;
        } else {
            return null;
        }

        $resding ["menu"] = trim($resding ["menu"]);

        $posstr = "外卖配送费";
        $pos = stripos($resding ["menu"], $posstr);
        $peisong = substr($resding ["menu"], $pos);

        $pos = stripos($peisong, ".");
        $shipping = substr($peisong, strlen($posstr), $pos + 3 - strlen($posstr));
        $resding ["shipping"] = trim($shipping);

        // 公司实收金额 = （userpay-运费+平台补贴）*0.95
        $income = ($resding ["userpay"] - $shipping - $resding ["platpay"]) * 0.95 + $shipping;
        $resding ["income"] = trim($income);
        $resding ["sid"] = $this->dmid;//"xbbxjkd"; // C ( "WMBAIDU" );
        // var_dump ( $resding );

        return $resding;
    }

    /*
     * !function(){require('wand:widget/common/order/order_list/table_menu_info/table_menu_info.js').createWidget( {
     * "content": {"total_price":"118.80",
     * "products":[
     * {"id":"1538409750","other_dish_id":"","name":"\u76ae\u76ae\u867e\u5927\u6218\u9999\u8fa3\u5927\u95f8\u87f9","current_price":"167.00","origin_price":"167.00","unit":"","left_num":976,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/abb697e7d98f1bdd71cc44addf1210af47","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"59","category_id":"1457958596","__menu_available":true,"number":1,"price":"167.00","total_price":"167.00","settle_price_more":"6.40","cart_id":"1","category_name":""},
     * {"id":"1532946526","other_dish_id":"","name":"\u00a59.9\u7279\u4ef7\u542e\u6307\u5364\u8150\u7af9","current_price":"9.90","origin_price":"9.90","unit":"","left_num":99998,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/d7cd8dae4fade99104a411ddaf32ba78a6","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"57","category_id":"1457958576","__menu_available":true,"number":1,"price":"9.90","total_price":"9.90","cart_id":"1","category_name":""},
     * {"id":"1532945839","other_dish_id":"","name":"\u00a59.9\u7279\u4ef7\uff0d\u79c1\u623f\u5364\u8c46\u76ae","current_price":"9.90","origin_price":"9.90","unit":"","left_num":99995,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/50f3be6bf856ed4362cbae5fe22eca1d61","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"56","category_id":"1457958576","__menu_available":true,"number":1,"price":"9.90","total_price":"9.90","cart_id":"1","category_name":""},
     * {"id":"1519585351","other_dish_id":"","name":"\u601d\u5ff5\u7092\u996d\uff08\u5c0f\u9f99\u867e\u7092\u996d\uff09","current_price":"35.00","origin_price":"35.00","unit":"","left_num":99994,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/255bde623721c1249af0ed839d71753231","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"44","category_id":"1520703545","__menu_available":true,"number":1,"price":"35.00","total_price":"35.00","cart_id":"1","category_name":""}],
     * "after_discount_price":"217.11","box_price":"0.00","dish_price":"221.80","real_total_price":"246.80","send_price":"25.00","product_price":"221.80","packgebox_billing_method":"new","settle_price_more":"6.40","discount_info":{"discount_list":[{"type":"te","discount":128,"subsidy":0,"desc":"\u7279\u4ef7\u4f18\u60e0","is_show_discount":1,"is_show_amount":0,"is_show_desc":1,"rule_id":0,"activity_id":0,"amount":0,"adesc":"","unit":"","products":{"1538409750":{"product_id":"1538409750","product_quantity":1,"orig_price":"167.00","activity_num":1,"from":"na-iphone","is_support_pay_offline":"0","is_support_pay_online":"1","is_conflict_activity":"1","rule_form":"constant","takeout_price":"1.00","activity_id":"9764","discount_limit":"0","order_num":"1","save_price":"128.00","dish_limit":"1","datetime":"20151231",
     * "content":{"baidu_rate":"0","shop_rate":"128","agent_rate":"0"},"dish_activity_quantity":1}},
     * "baidu_rate":0,"shop_rate":128,"agent_rate":0}],"show_list":[],"is_discount_first_order":0,"subsidy":0,"baidu_rate":0,"shop_rate":128,"agent_rate":0,"logistics_rate":0,"discount_send_price":"0.00","discountprice":"128.00","is_discount_send":0,"takeout_cost":25},
     * "coupon_info":{"1":""},"cart_num":1,"show_original_price":true,"discount_display":{"baidu_rate":0,"shop_rate":128,"agent_rate":0,"logistics_rate":0,"subsidy_total":128,"subsidy_total_display":"128.00","subsidy_list_display":[]},"count_product":4},
     * "logistics_type": "not_baidu_wuliu",
     * "shopUserCategory1Name": "餐饮",
     * "part_total_price": "221.80",
     * "colspan_length": "3",
     * "order_id": "14515565141934"
     * });
     * }();
     * !function(){ require('wand:widget/common/order/map/map.js').createWidget({
     * data:{"order_id":"14515560971946","order_index":"31","flag":[],"supplier_id":"0","pass_uid":"1427829008","pass_phone":"18601077038","user_note":"","send_time":"1","channel_from":"na-iphone","confirm_time":"1451556116","finished_time":"1451574125","total_price":"143.00","order_price":"363.00","shop_show_price":"143.00","shop_visible":1,"status":9,"create_time":1451556105,"cancel_reason_status":"0","coupon_info":"[]","delivery_party":"self","source_name":"1","is_commented":"2","curr_delivery_time":"60","pay_status":"1","pay_type":"1","paid_time":1451556105,"content":{"total_price":"143.00","products":[{"id":"1538409750","other_dish_id":"","name":"\u76ae\u76ae\u867e\u5927\u6218\u9999\u8fa3\u5927\u95f8\u87f9","current_price":"167.00","origin_price":"167.00","unit":"","left_num":977,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/abb697e7d98f1bdd71cc44addf1210af47","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"59","category_id":"1457958596","__menu_available":true,"number":1,"price":"167.00","total_price":"167.00","settle_price_more":"6.40","cart_id":"1","category_name":""},{"id":"1528929424","other_dish_id":"","name":"\u867ebaby\u6700\u7545\u9500\u76845\u6b3e\u5c0f\u98df\u7ec4\u5408","current_price":"171.00","origin_price":"171.00","unit":"","left_num":99991,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/fec8c2898b41eb9a7097a41f27382d8958","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"50","category_id":"1481614896","__menu_available":true,"number":1,"price":"171.00","total_price":"171.00","settle_price_more":"4.60","cart_id":"1","category_name":""}],"after_discount_price":"332.10","box_price":"0.00","dish_price":"338.00","real_total_price":"363.00","send_price":"25.00","product_price":"338.00","packgebox_billing_method":"new","settle_price_more":"11.00","discount_info":{"discount_list":[{"type":"te","discount":220,"subsidy":0,"desc":"\u7279\u4ef7\u4f18\u60e0","is_show_discount":1,"is_show_amount":0,"is_show_desc":1,"rule_id":0,"activity_id":0,"amount":0,"adesc":"","unit":"","products":{"1538409750":{"product_id":"1538409750","product_quantity":1,"orig_price":"167.00","activity_num":1,"from":"na-iphone","is_support_pay_offline":"0","is_support_pay_online":"1","is_conflict_activity":"1","rule_form":"constant","takeout_price":"1.00","activity_id":"9764","discount_limit":"0","order_num":"1","save_price":"128.00","dish_limit":"1","datetime":"20151231","content":{"baidu_rate":"0","shop_rate":"128","agent_rate":"0"},"dish_activity_quantity":1},"1528929424":{"product_id":"1528929424","product_quantity":1,"orig_price":"171.00","activity_num":1,"from":"na-iphone","is_support_pay_offline":"0","is_support_pay_online":"1","is_conflict_activity":"1","rule_form":"constant","takeout_price":"1.00","activity_id":"7117","discount_limit":"0","order_num":"1","save_price":"92.00","dish_limit":"10","datetime":"20151231","content":{"baidu_rate":"0","shop_rate":"92","agent_rate":"0"},"dish_activity_quantity":1}},"baidu_rate":0,"shop_rate":220,"agent_rate":0}],"show_list":[],"is_discount_first_order":0,"subsidy":0,"baidu_rate":0,"shop_rate":220,"agent_rate":0,"logistics_rate":0,"discount_send_price":"0.00","discountprice":"220.00","is_discount_send":0,"takeout_cost":25},"coupon_info":{"1":""},"cart_num":1,"show_original_price":true,"discount_display":{"baidu_rate":0,"shop_rate":220,"agent_rate":0,"logistics_rate":0,"subsidy_total":220,"subsidy_total_display":"220.00","subsidy_list_display":[]},"count_product":2},"logistics_shop_price":"14300.00","user_phone":"18601077038","user_real_name":"\u738b\u80d6\u5b50","user_address":"\u5317\u4eac\u5916\u56fd\u4e13\u5bb6\u5927\u53a6 3\u53f7\u697c2207","city_id":"131","city_name":"\u5317\u4eac","aoi_id":"9032677458467127863","shop_id":"205670","shop_name":"\u867ebaby\u5c0f\u9f99\u867e\uff08\u5267\u7a7a\u95f4\u9910\u5385\uff09","shop_phone":"4000-365-617","sms_receive_phone":"","waimai_release_id":"1454986052","last_remind_time":0,"user_remind_times":0,"invoice_title":"","need_invoice":0,"cancel_reason":"","sex":"2","logistics_id":0,"delivery_phone":"","delivery_name":"","order_type":0,"set_express":0,"ext":{"nickname":"","user_address_lng":"12956444.18004652","user_address_lat":"4837247.441805112","user_address_component":"\u5317\u4eac\u5e02\u671d\u9633\u533a\u5317\u56db\u73af\u4e2d\u8def\u8f85\u8def","delivery_delay_time":"0","lt":"0","settlement_callback":{"time_type":1,"settlement_party":"shop","settlement_type":5,"delivery_type":1},"deliver_after_day":0,"shop_prepare_time":null,"expect_arrived_time":1451559704,"is_print":0,"auto_confirm_order":0,"express_type":"","express_id":"","express_company":"","user_address_detail":"\u5317\u4eac\u5e02\u671d\u9633\u533a\u5317\u56db\u73af\u4e2d\u8def\u8f85\u8def\u5317\u4eac\u5916\u56fd\u4e13\u5bb6\u5927\u53a6 3\u53f7\u697c2207"},"responsible_party":"","total_order_count":27,"complete_order_count":24,"new_delivery_party":"self","mobile_order_label":[{"name":"\u5728\u7ebf\u652f\u4ed8","color":"green"}],"mobile_order_type":[],"pc_order_label":[{"name":"\u5728\u7ebf\u652f\u4ed8","color":"#88c800","is_card_show":0}],"pc_order_type":"","shop_info":{"location_shop":{"longitude":"12955433.95","latitude":"4831083.99"},"shop_address":"\u65b0\u8857\u53e3\u5317\u5927\u885774\u53f78-12\u5e62"},"takeout_phone":"4000-365-617","takeout_average_time":"0","pay_display":1,"delivery_staff_phone":"","is_ranger_show":0,"real_status":9,"range_status":1,"distance":"<4.8\u5343\u7c73","is_show_express":0,"delivery_delay_time":0,"pass_name":"","auto_confirm_order":0,"is_print":0,"display_discount":false,"delivery_status":0,"send_meal_time":0,"comment_delivery_status":0,"comment_show_status":0},
     *
     * index:12
     * });
     * }();
     * !function(){require('wand:widget/common/order/order_list/table_menu_info/table_menu_info.js').createWidget( {
     * "content": {"total_price":"143.00","products":[
     * {"id":"1538409750","other_dish_id":"","name":"\u76ae\u76ae\u867e\u5927\u6218\u9999\u8fa3\u5927\u95f8\u87f9","current_price":"167.00","origin_price":"167.00","unit":"","left_num":977,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/abb697e7d98f1bdd71cc44addf1210af47","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"59","category_id":"1457958596","__menu_available":true,"number":1,"price":"167.00","total_price":"167.00","settle_price_more":"6.40","cart_id":"1","category_name":""},{"id":"1528929424","other_dish_id":"","name":"\u867ebaby\u6700\u7545\u9500\u76845\u6b3e\u5c0f\u98df\u7ec4\u5408","current_price":"171.00","origin_price":"171.00","unit":"","left_num":99991,"soldout":1,"special":1,"takeaway_menu_dishpic":"http:\/\/img.waimai.bdimg.com\/pb\/fec8c2898b41eb9a7097a41f27382d8958","sell_number":0,"min_order_number":1,"packge_box_price":"0.00","packge_box_number":"1","discount":"95","bar_code":"","have_attr":"0","have_feature":"0","dish_type":1,"rank":"50","category_id":"1481614896","__menu_available":true,"number":1,"price":"171.00","total_price":"171.00","settle_price_more":"4.60","cart_id":"1","category_name":""}
     * ],"after_discount_price":"332.10","box_price":"0.00","dish_price":"338.00","real_total_price":"363.00","send_price":"25.00","product_price":"338.00","packgebox_billing_method":"new","settle_price_more":"11.00","discount_info":{"discount_list":[{"type":"te","discount":220,"subsidy":0,"desc":"\u7279\u4ef7\u4f18\u60e0","is_show_discount":1,"is_show_amount":0,"is_show_desc":1,"rule_id":0,"activity_id":0,"amount":0,"adesc":"","unit":"","products":{"1538409750":{"product_id":"1538409750","product_quantity":1,"orig_price":"167.00","activity_num":1,"from":"na-iphone","is_support_pay_offline":"0","is_support_pay_online":"1","is_conflict_activity":"1","rule_form":"constant","takeout_price":"1.00","activity_id":"9764","discount_limit":"0","order_num":"1","save_price":"128.00","dish_limit":"1","datetime":"20151231","content":{"baidu_rate":"0","shop_rate":"128","agent_rate":"0"},"dish_activity_quantity":1},"1528929424":{"product_id":"1528929424","product_quantity":1,"orig_price":"171.00","activity_num":1,"from":"na-iphone","is_support_pay_offline":"0","is_support_pay_online":"1","is_conflict_activity":"1","rule_form":"constant","takeout_price":"1.00","activity_id":"7117","discount_limit":"0","order_num":"1","save_price":"92.00","dish_limit":"10","datetime":"20151231","content":{"baidu_rate":"0","shop_rate":"92","agent_rate":"0"},"dish_activity_quantity":1}},"baidu_rate":0,"shop_rate":220,"agent_rate":0}],"show_list":[],"is_discount_first_order":0,"subsidy":0,"baidu_rate":0,"shop_rate":220,"agent_rate":0,"logistics_rate":0,"discount_send_price":"0.00","discountprice":"220.00","is_discount_send":0,"takeout_cost":25},"coupon_info":{"1":""},"cart_num":1,"show_original_price":true,"discount_display":{"baidu_rate":0,"shop_rate":220,"agent_rate":0,"logistics_rate":0,"subsidy_total":220,"subsidy_total_display":"220.00","subsidy_list_display":[]},"count_product":2},
     * "logistics_type": "not_baidu_wuliu",
     * "shopUserCategory1Name": "餐饮",
     * "part_total_price": "338.00",
     * "colspan_length": "3",
     * "order_id": "14515560971946"
     * });
     * }();
     */

    /**
     * 返回数组 ，每组数据格式
     *
     * 总订单号， 子订单
     *
     * 还是要有个统一的规则
     *
     * 1 把有子订单的入库，没有的后续单独处理来生成子订单号
     * 2 列一下明细用于显示详情
     *
     * 3 返回拼出来 子订单的内容，用于给主订单入库
     * 同时确认是否存在子订单已经入库了
     *
     * 子订单的详情用于单独入库
     * {"id":"1538409750","name":"\u76ae\u76ae\u867e\u5927\u6218\u9999\u8fa3\u5927\u95f8\u87f9",
     * "current_price":"167.00","origin_price":"167.00","soldout":1,
     * ,"packge_box_number":"1","number":1,"price":"167.00","total_price":"167.00","settle_price_more":"6.40",},
     *
     *
     *
     * 4 子订单保存入库
     */
//    public function dealfunctionorder($url, &$datas, &$menus)
    public function dealfunctionorder($html, &$datas, &$menus)
    {
//		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";

        // $path = C ( 'SS_CACHEPATH' );
        // $uri = C ( 'XBB_URI' );
        // $url = $uri . $path . "20151201-20151231-2";

        // $url="http://localhost/tpxbb/public/pcdb/20151201-20151231-1";
        // $url ="http://localhost/tpxbb/public/pc/2016-01-17_2016-01-03_46";
        // echo $url;

        //
        $funbegin = "table_menu_info.js').createWidget(";
        $funend = ");";

//        $res = file_get_contents($url);

        $res = $html;
        $pos = 0;



        $funlen = strlen($funbegin);
        $endlen = strlen($funend);

        $conarray = array();


        $content = "";

        while ($pos >= 0) {

            // 定位到第一个 子订单
            $pos = stripos($res, $funbegin);
            if ($pos == null || $pos == "") {

                // echo "pos=null" . $pos . "</br>";
                break;
            }

            // echo "pos=" . $pos . "</br>";

            // 截取 第一段内容的开始
            $res = substr($res, $funlen + $pos);
            $pos = stripos($res, $funend);

            // echo "pos2=" . $pos . "</br>";

            $content = substr($res, 0, $pos);

            // array_push ( $conarray, $content );
            $this->getsuborder($content, $datas, $menus);

            $res = substr($res, $pos + $endlen);

            // break;
        }

        // echo "datas count=" . count ( $datas );
        // echo "</br>menus count=" . count ( $menus );

        // 存贮子订单
        $subding = M("subdingdan");

        // $list = $subding->field ( "subid" )->select ();
        // var_dump($list);

        foreach ($datas as $key => $value) {
            $num = count($value);

            for ($i = 0; $i < $num; $i++) {
                try {

                    // echo $value[$i]["subid"]."</br>";
                    $subid = $value [$i] ["subid"];



                    $this->dbsubdingdan [$subid] = $value [$i];
                } catch (\Think\Exception $e) {

                    Log::record($e->getMessage(), "ERR");;

                }
            }
        }
    }

    /**
     * 返回子订单数组, 子订单号， 菜名，数量，价格
     *
     *
     * 返回 子订单字符串
     *
     * datas[order_id]= 子订单数组；
     */
    function getsuborder($content, &$datas, &$menus)
    {
        // echo $content;
        $de_json = json_decode($content, true);
        $count_json = count($de_json);

        // foreach ( $de_json as $key => $value ) {
        // echo $key . " " . $value;
        // // var_dump($value);

        // echo "</br></br></br>";
        // }

        // echo $count_json."</br></br></br></br></br>";

        // var_dump($de_json);

        // echo count ( $de_json ["content"] ) . "</br></br></br></br></br>";
        // var_dump ( $de_json ["content"] );

        $menu = "";

        $decontent = $de_json ["content"];

        $datasubs = array();

        foreach ($decontent as $key => $value) {

            if ($key == "products") {
                // echo "key=" . $key . "</br>";
                // var_dump($value);

                $products = $value;

                for ($i = 0; $i < count($products); $i++) {

                    $product = $products [$i];

                    $menu = $menu . $product ["name"] . "  " . $product ["current_price"] . "  " . $product ["number"] . "  ";

                    $data = array();
                    $data ["ddid"] = trim($de_json ["order_id"]);
                    $data ["subid"] = trim($data ["ddid"] . $i);
                    $data ["menu_id"] = trim($product ["id"]);
                    $data ["name"] = trim($product ["name"]);
                    $data ["current_price"] = trim($product ["current_price"]);
                    $data ["origin_price"] = trim($product ["origin_price"]);
                    $data ["number"] = $product ["number"];
                    $data ["total_price"] = $product ["total_price"];

                    array_push($datasubs, $data);

                    // var_dump($data);

                    // foreach ( $products [$i] as $ppkey => $ppvalue ) {
                    // echo "" . $ppkey . " " . $ppvalue . "</br>";
                    // }
                }
            } else {
                // echo "key=" . $key . " value=" . $value . "</br>";
                // var_dump ( $value );

                // $totalmenu["total_price"]= $de_json["total_price"];
                // $totalmenu["send_price"]= $de_json["send_price"];
            }

            // echo "</br></br></br>";
        }

        $order_id = trim(($de_json ["order_id"]));

        $datas [$order_id] = $datasubs;

        $menu = $menu . "运费" . $decontent ["send_price"] . "  总计：" . $decontent ["total_price"];

        // $oid=(string)$order_id;
        // echo "order_id=".$order_id." type=".gettype($order_id)."</br>";
        $menus [$order_id] = trim($menu);

        // echo "order_id=".$order_id;
        // echo "menu=".$menu;

        // return $menu;
    }

    public function dealcsv2()
    {
        // $filename = "/Users/jdong/project/tpxbb/public/uploads/56a33c0a0bdef.csv";

        // // 载入文件，基于服务器的路径

        // // 遍历pc目录下所有缓存文件

        // $file = fopen ( $filename, "r" );

        // while ( ! feof ( $file ) ) {

        // var_dump ( fgetcsv ( $file ) );
        // echo "</br></br></br>";
        // }

        // fclose ( $file );

        /*
         *
         * array(37) {
         * [0]=> string(1) "2"
         * [1]=> string(17) "="14500599007758""
         * [2]=> string(0) ""
         * [3]=> string(4) "北京"
         * [4]=> string(4) "null"
         * [5]=> string(26) "虾baby小龙虾（剧空间餐厅）"
         * [6]=> string(6) "沈少辉"
         * [7]=> string(17) "清缘东里 1-4-1201"
         * [8]=> string(123) "麻辣小龙虾盖饭（预定）_15日12点前送餐*38.0*1.0/不拘一蛤（辣炒花蛤）*38.0*1.0/红烧小龙虾盖饭（预定）_15日12点前送餐*38.0*1.0"
         * [9]=> string(0) ""
         * [10]=> string(10) "2015-12-14"
         * [11]=> string(5) "10:25"
         * [12]=> string(5) "10:26"
         * [13]=> string(1) "0"
         * [14]=> string(0) ""
         * [15]=> string(3) "126" 发票金额
         * [16]=> string(4) "即时"
         * [17]=> string(8) "立即送餐"
         * [18]=> string(8) "线上支付"
         * [19]=> string(6) "已完成"
         * [20]=> string(0) ""
         * [21]=> string(0) ""
         * [22]=> string(3) "114" 菜品原价金额
         * [23]=> string(1) "0" 餐盒费
         * [24]=> string(2) "20" 配送费
         * [25]=> string(3) "134" 订单总金额
         * [26]=> string(1) "0" 免配送费"
         * [27]=> string(3) "5.7" 百度折扣佣金
         * [28]=> string(1) "0" 商户补贴金额"
         * [29]=> string(1) "8" 平台补贴金额
         * [30]=> string(3) "126" 商户应收金额
         * [31]=> string(3) "126" 用户支付金额
         * [32]=> string(5) "128.3" 百度理论结算金额
         * [33]=> string(1) "0"
         * [34]=> string(1) "0"
         * [35]=> string(1) "0"
         * [36]=> string(0) "" }
         *
         *
         *
         * http://wmcrm.baidu.com/crm?qt=orderlist&order_status=0&start_time=2015-12-01&end_time=2015-12-31&pay_type=2&is_asap=0
         * http://wmcrm.baidu.com/crm?qt=orderlist&order_status=0&start_time=2015-12-01&end_time=2015-12-31&pay_type=2&is_asap=0&page=2
         *
         */
    }
//	public function login() {
//		require_once C ( 'CUSTOM_LIBRARY' ) . '/httpful-2.phar';
//
//		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
//		// echo "百度外卖";
//
//		$cookiearray=array(
//			"cw"=>"BIDUPSID=A8BB23A27ED38837E2852FC26650C039; PSTM=1435029601; BAIDUID=70D8D286E302085DD98C6A5575EFCD49
//:FG=1; BDRCVFR[Fc9oatPmwxn]=srT4swvGNE6uzdhUL68mv3; H_PS_PSSID=1434_18696_18282_17944_15956_12328_10634
//; BDRCVFR[gltLrB7qNCt]=mk3SLVN4HKm; WMUSS=AAIsDAAB1KhlQM3ZEXxA5KEwWPwcIBAw7DUZeRSFeKzZbYygcWVE0KQUrbWQ7Jg0HiAAAPEwOQ1AZflxfXCJ
//%7EO002FzFeMgovZjM0EiAZTEYmUwJxYEVBeUMeWCA%7EV1oNDnE9ayNGGwp4TxsYZ2deDTpffhquYdcAGjMqEPHqfwyJLoQQb%7EJBAbkhVReFmBU
//; _wmcrmpush=E48678295373CA76A9E978281C3CE03A_1455072276_10_1454986052_xbabyxjkd0-7D4C07CD3F149F1960
//029A2F447B7671_1455159056_10_1533034181_xiababy0-8D4EBA7661C45EA99A09DC3FF677241A_1455161951_10_1483976135_xiababycw0
//; newyear=open; isReadLetter=read; BCLID=3824686292385933078; BDSFRCVID=1CLsJeCAaGij9fR4lK-M25WbR2KK0gOTH6KFQDRASSsGFYCVJKjvSH0PtOlQpYD-J__TogKK0gOTH65P
//; H_BDCLCKID_SF=tR4HoDPatKvbfP0kjjQD-t4D5eT22jnb3gneaJ5nJDoTSIjTX5-M2hFPhGKtL-jNBCjJXxolQpP-HJ7ah-I-
//hJK_bUn2JMRp0KQDKl0MLpF5DMjxWf8Ve-cLDfnMBMPjamOnaPQtLIFKhK06DjAKePDqql6tetoX2jTW06rJabC3jKnMKU6qLT5X
//htr3WJLtJTbkoI0-Jx3DVCoo-qrThl0njxQyXfotMJ7NhpCK5Rv4jDjK5xonDh83XUvIbpcRHGOCaI5O5hvvhb6O3M7--lOhDNte
//J6FOtJ3EBnTeKRA_HRjYbb__-P4DeNQmWnJZ5m7C3l3V2DTtVCb1yIcYD6Li-RKHBMPj52OnaIQc3fjUVljb0nbnQlFd346iaJ5gWnRTLp7sL4JZs56_BpnxhP-UyN3MWh37JJTTVJO-KKC-hKKmDxK
//; new_order_time=1455161950; new_remind_time=1455161920; MCITY=-213%3A",
//
//"xjkny"=>"BIDUPSID=B86659B6FB22D32206E3640E6CE944A4; PSTM=1435029601; BAIDUID=70D8D286E302085DD98C6A5575EFCD49
//:FG=1; BDRCVFR[Fc9oatPmwxn]=srT4swvGNE6uzdhUL68mv3; H_PS_PSSID=1434_18282_17944_15405_12328_10634; BDRCVFR
//[gltLrB7qNCt]=mk3SLVN4HKm; WMUSS=AALkCAABfJkdAaUVdTDQIeiQiHg1JcQcbTj86MFtrMX8ePFVXHHoeW2RiOTEXQSs73FNRAQmawRP8eAAAYklHLDpORggNAThna2hnCiU8YUE3fh0bYVVLdxd2Mnk
//%7EeCV5RmsCU2s5OlciIWBGXUIHFEAkLyF4ehgPcEkJMEIs3QYBVEIvDXSuSQ5q2fwLQBM; _wmcrmpush=E48678295373CA76A9E978281C3CE03A_1455072276_10_1454986052_xbabyxjkd0
//; new_remind_time=1454985944; newyear=open; isReadLetter=read",
//
//"xjk"=>"BAIDUPSID=F079717ADD00CD36C726E29582733F2C; BIDUPSID=8CFCCD01533681A17A64145177FE0D5D; BAIDUID=05162CB9BB596063826F96A7C7BC47A0
//:FG=1; PSTM=1432819942; BDRCVFR[gltLrB7qNCt]=mk3SLVN4HKm; H_PS_PSSID=18451_1429_18724_18284_12824_18790_18731_18767_18777_18546_18780_17000_18781_17072_15350_12136_17997
//; WMUSS=AEECAABvdT8RDE91ExFuFllMaT8EbhQUN0srYU8gMXFMKzULGipJKzYZIEgpD10DQAAW0dBXjVUcmwgHU5uPX9fCSoVE
//0M-XG50dA49Hh0bIHdhYVYXNUgDVGVRQiJQIip5Nj09dBkraA45JitVQEpNIiss1MkAVBX-C3Q13RFqYJAP3FNRAVOQwRN3mNBUA
//; new_order_time=1452499288; _wmcrmpush=FAF068B852B353305687872C8EEC425D_1452499288_10_1454986052_xbabyxjkd0
//; new_remind_time=1452499258"
//
//
//		);
//
//		$cookie=$cookiearray["cw"];
//
//		// 载入cookie数据
//
//// 		$cookie = "BAIDUPSID=F079717ADD00CD36C726E29582733F2C; BIDUPSID=8CFCCD01533681A17A64145177FE0D5D; BAIDUID=05162CB9BB596063826F96A7C7BC47A0
//// :FG=1; PSTM=1432819942; BDRCVFR[gltLrB7qNCt]=mk3SLVN4HKm; H_PS_PSSID=18451_1429_18724_18284_12824_18790_18731_18767_18777_18546_18780_17000_18781_17072_15350_12136_17997
//// ; WMUSS=AEECAABvdT8RDE91ExFuFllMaT8EbhQUN0srYU8gMXFMKzULGipJKzYZIEgpD10DQAAW0dBXjVUcmwgHU5uPX9fCSoVE
//// 0M-XG50dA49Hh0bIHdhYVYXNUgDVGVRQiJQIip5Nj09dBkraA45JitVQEpNIiss1MkAVBX-C3Q13RFqYJAP3FNRAVOQwRN3mNBUA
//// ; new_order_time=1452499288; _wmcrmpush=FAF068B852B353305687872C8EEC425D_1452499288_10_1454986052_xbabyxjkd0
//// ; new_remind_time=1452499258";
//
//
//// 		   $cookie = "BIDUPSID=B86659B6FB22D32206E3640E6CE944A4; PSTM=1435029601; BAIDUID=70D8D286E302085DD98C6A5575EFCD49
//// :FG=1; BDRCVFR[Fc9oatPmwxn]=srT4swvGNE6uzdhUL68mv3; H_PS_PSSID=1434_18282_17944_15405_12328_10634; BDRCVFR
//// [gltLrB7qNCt]=mk3SLVN4HKm; WMUSS=AALkCAABfJkdAaUVdTDQIeiQiHg1JcQcbTj86MFtrMX8ePFVXHHoeW2RiOTEXQSs73FNRAQmawRP8eAAAYklHLDpORggNAThna2hnCiU8YUE3fh0bYVVLdxd2Mnk
//// %7EeCV5RmsCU2s5OlciIWBGXUIHFEAkLyF4ehgPcEkJMEIs3QYBVEIvDXSuSQ5q2fwLQBM; _wmcrmpush=E48678295373CA76A9E978281C3CE03A_1455072276_10_1454986052_xbabyxjkd0
//// ; new_remind_time=1454985944; newyear=open; isReadLetter=read";
//
//		$cookie = preg_replace ( '/[\r\n]+/', '', $cookie );
//		$headers = array (
//				'Cookie' => $cookie,
//				'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0'
//		);
//
//// 	  var_dump($cookie);
//
//		// $url = "http://wmcrm.baidu.com/crm?qt=orderlist&order_status=0&start_time=2016-01-05&end_time=2016-01-06&pay_type=2&is_asap=0";
//		$start="2016-02-01";
//		$end="2016-02-31";
//		$start2="20160201";
//		$end2="20160231";
//		$suffix="cw";
//
//		for($x = 1; $x < 50; $x ++) {
//
//			$url = "http://wmcrm.baidu.com/crm?qt=orderlist&order_status=0&start_time=".$start."&end_time=".$end."&pay_type=2&is_asap=0&page=" . $x;
//
//			Log: $url."</br>";
//
//			$request = \Httpful\Request::get ( $url )->addHeaders ( $headers );
//			$resp = $request->withoutAutoParsing ()->send ();
//
//			$content = $resp->body;
//
//// 			var_dump ( $content );
//			$valistr = "顾客电话";
//
//			$pos = stripos ( $content, $valistr );
//
//
//
//			if ($pos > 10) {
//				$filename = $this->pcDir.$start2."-".$end2.$suffix.$x;
//
//				if (file_exists ( $filename )) {
//					continue;
//				}
//
//				$res = file_put_contents ( $filename, $content );
//			} else {
//
//				Log::record( "total page=" . $x,"DEBUG");
//				break;
//			}
//		}
//
//		// $this->display ();
//	}
}